package com.hb.trans.mvp.ui.activity


import android.os.Bundle
import android.view.MenuItem
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.basiclib.base.BaseActivity
import com.hb.trans.R
import com.hb.trans.bean.MyMenu
import com.hb.trans.global.ACTIVITY_CENTER_LIST
import com.hb.trans.mvp.contract.CenterListContract
import com.hb.trans.mvp.presenter.NewDetailPresenter
import com.hb.trans.mvp.ui.adapter.CenterListAdapter
import dagger.android.AndroidInjection
import kotlinx.android.synthetic.main.activity_center_list.*
import javax.inject.Inject


@Route(path = ACTIVITY_CENTER_LIST)
class CenterListActivity : BaseActivity(), CenterListContract.View {


    @Inject
    lateinit var mAdapter1: CenterListAdapter
    @Inject
    lateinit var mAdapter2: CenterListAdapter
    @Inject
    lateinit var mAdapter3: CenterListAdapter
    @Inject
    override fun getContentViewResId(): Int = R.layout.activity_center_list

    var page:Int = 1



    private val menus1 = mutableListOf(
        MyMenu(head = "130100", name = "1"),
        MyMenu(head = "130200", name = "2"),
        MyMenu(head = "130300", name = "3"),
        MyMenu(head = "130300", name = "4"),
        MyMenu(head = "130300", name = "5"),
        MyMenu(head = "130300", name = "6")
    )
    private val menus2 = mutableListOf(
        MyMenu(head = "130100", name = "11"),
        MyMenu(head = "130200", name = "21"),
        MyMenu(head = "130300", name = "31"),
        MyMenu(head = "130300", name = "41"),
        MyMenu(head = "130300", name = "51"),
        MyMenu(head = "130300", name = "61")
    )
    private val menus3 = mutableListOf(
        MyMenu(head = "130100", name = "13"),
        MyMenu(head = "130200", name = "23"),
        MyMenu(head = "130300", name = "33"),
        MyMenu(head = "130300", name = "43"),
        MyMenu(head = "130300", name = "53"),
        MyMenu(head = "130300", name = "63")
    )

    override fun onActivityInject() {
        AndroidInjection.inject(this)
    }

    override fun attachView(savedInstanceState: Bundle?) {
        ARouter.getInstance().inject(this)
    }

    override fun getPresenter(): NewDetailPresenter? = null

    override fun initView() {
        setSupportActionBar(centerListToolbar.toolbar)
        supportActionBar!!.setDisplayHomeAsUpEnabled(true)
        supportActionBar!!.setHomeAsUpIndicator(R.mipmap.ic_left_arrow)
        initMenu()
    }

    override fun onOptionsItemSelected(item: MenuItem): Boolean {
        when (item.itemId) {
            android.R.id.home -> {
                when(page){
                    1 ->  onBackPressed()
                    2 ->  {
                        page = 1
                        center_list_list.adapter = mAdapter1
                    }
                    3 ->  {
                        page = 2
                        center_list_list.adapter = mAdapter2
                    }
                }


            }
        }
        return true
    }

    override fun initData() {
    }

    override fun setListener() {

        mAdapter1.setOnItemClickListener { adapter, _, position ->

            center_list_list.adapter = mAdapter2
            page = 2
        }
        mAdapter2.setOnItemClickListener { adapter, _, position ->
            center_list_list.adapter = mAdapter3
            page = 3
        }
        mAdapter3.setOnItemClickListener { adapter, _, position ->
            when(position){
                1 -> showShortToast(position.toString())
                2 -> showShortToast(position.toString())
                3 -> showShortToast(position.toString())
                5 -> showShortToast(position.toString())
                else -> {
                    showShortToast(position.toString())
                }
            }
        }

    }

    private fun initMenu(){

        mAdapter1.setNewData(menus1)
        mAdapter2.setNewData(menus2)
        mAdapter3.setNewData(menus3)
        center_list_list.apply {
            adapter = mAdapter1
        }



    }


}
